
from selenium import webdriver  # 浏览器驱动器
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By  # 定位器
from selenium.webdriver.common.keys import Keys  # 键盘对象
from selenium.webdriver.support import expected_conditions as EC  # 判断器
from selenium.webdriver.support.wait import WebDriverWait  # 浏览器等待对像
#
from time import sleep
#1.创建Chrome浏览器对象，这会在电脑上在打开一个浏览器窗口,需要下载webdriver
#browser = webdriver.Chrome(executable_path ="D:\GDriver\chromedriver.exe")
s = Service(r"D:\GDriver\chromedriver.exe")
driver = webdriver.Chrome(service=s)
#2.通过浏览器向服务器发送URL请求
driver.get("http://smartplan.longfor.uat/")

sleep(3)

#3.刷新浏览器
driver.refresh()

#4.设置浏览器的大小
#browser.set_window_size(1400,800)

sleep(5)
#5.设置链接内容   //*[@id="app"]/div/div/div[2]/form/div[1]/div/div/input
username = driver.find_element_by_xpath("/html/body/div/div/div/div[2]/form/div[1]/div/div/input")#.send_keys("luyan3")
print(username)
username.send_keys("luyan3")
driver.find_element_by_xpath('/html/body/div/div/div/div[2]/form/div[2]/div/div/input').send_keys("@WSX1qaz")

driver.find_element_by_xpath('//*[@id="app"]/div/div/div[2]/form/button').click()

sleep(3)
#搜索大井峪天钜 项目
driver.find_element_by_xpath('//*[@id="app"]/div/div/div[3]/div/div[1]/div/div/div/div/div[1]/div[2]/div[1]/div/input').send_keys('大井峪天钜')
driver.find_element_by_xpath('//*[@id="app"]/div/div/div[3]/div/div[1]/div/div/div/div/div[1]/div[2]/div[1]/div/input').send_keys(Keys.ENTER)
sleep(3)
driver.find_element_by_xpath('//*[@id="pane-91b054db-a672-41e8-82fb-86cd7ed81bd7"]/span[1]').click()
sleep(3)
all_window=driver.window_handles
current_window = driver.current_window_handle 
for window in all_window:
    if window != current_window:
        driver.switch_to.window(window)
driver.find_element_by_xpath('/html/body/div[3]/div/div/div[2]/div/div/div/div[3]/div/div[2]/div[3]/div[2]/a[2]').click()

#driver.close()
